import 'package:flutter/material.dart';
import 'package:flutter_bilibili/model/video_detail_mo.dart';
import 'package:flutter_bilibili/util/color_util.dart';
import 'package:flutter_bilibili/util/format_util.dart';
import 'package:flutter_bilibili/util/view_util.dart';

/// 视频点赞分享收藏等工具栏
class VideoToolbar extends StatelessWidget {
  final VideoDetailMo videoDetailMo;
  final VoidCallback? onLike;
  final VoidCallback? onUnlike;
  final VoidCallback? onCoin;
  final VoidCallback? onFavorite;
  final VoidCallback? onShare;

  const VideoToolbar({
    super.key,
    required this.videoDetailMo,
    this.onLike,
    this.onUnlike,
    this.onCoin,
    this.onFavorite,
    this.onShare,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.only(top: 15, bottom: 10),
      margin: const EdgeInsets.only(bottom: 15),
      decoration: BoxDecoration(
        border: borderLine(context),
        color: Colors.white60,
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: [
          _buildIconText(
            Icons.thumb_up_alt_rounded,
            videoDetailMo.like,
            onClick: onLike,
            tint: videoDetailMo.isLike,
          ),
          _buildIconText(
            Icons.thumb_down_alt_rounded,
            '不喜欢',
            onClick: onUnlike,
            tint: videoDetailMo.isUnlike,
          ),
          _buildIconText(
            Icons.monetization_on,
            videoDetailMo.coin,
            onClick: onCoin,
          ),
          _buildIconText(
            Icons.grade_rounded,
            videoDetailMo.favorite,
            onClick: onFavorite,
            tint: videoDetailMo.isFavorite,
          ),
          _buildIconText(
            Icons.share_rounded,
            videoDetailMo.share,
            onClick: onShare,
          ),
        ],
      ),
    );
  }

  _buildIconText(IconData iconData, text, {onClick, bool tint = false}) {
    if (text is int) {
      text = countFormat(text);
    }
    return InkWell(
      onTap: onClick,
      child: Column(
        children: [
          Icon(iconData, color: tint ? primary : Colors.grey),
          hiSpace(height: 5),
          Text(text, style: const TextStyle(color: Colors.grey, fontSize: 12))
        ],
      ),
    );
  }
}
